//
// Created by 123 on 2024/3/3.
//
#include <iostream>

#define MaxSize 10

using namespace std;


typedef struct {
    int data[MaxSize];
    int front, rear;

} SqQueue;

//初始化
void initQueue(SqQueue &sqQueue);

//判空
bool isEmpty(SqQueue sqQueue);

//进队列
bool enQueue(SqQueue &sqQueue, int e);

//出队列
bool deQueue(SqQueue &sqQueue, int &e);

//获取头
bool getHead(SqQueue sqQueue, int &e);

void show(SqQueue s);


int main() {
    SqQueue s;
    initQueue(s);
    show(s);

    enQueue(s, 1);
    enQueue(s, 2);
    enQueue(s, 3);
    enQueue(s, 4);
    enQueue(s, 5);
    show(s);
    int e = -1;
    deQueue(s, e);
    cout << e << "   <-----------" << endl;
    show(s);
    deQueue(s, e);
    cout << e << "   <-----------" << endl;
    show(s);
    deQueue(s, e);
    cout << e << "   <-----------" << endl;
    show(s);
    deQueue(s, e);
    cout << e << "   <-----------" << endl;
    show(s);
    deQueue(s, e);
    cout << e << "   <-----------" << endl;
    show(s);
    cout<<enQueue(s,1)<<endl;
    cout<<enQueue(s,1)<<endl;
    cout<<enQueue(s,1)<<endl;
    cout<<enQueue(s,1)<<endl;
    cout<<enQueue(s,1)<<endl;
    cout<<enQueue(s,1)<<endl;
    cout<<enQueue(s,1)<<endl;
    cout<<enQueue(s,1)<<endl;
    cout<<enQueue(s,1)<<endl;
    show(s);
    cout<<enQueue(s,1)<<endl;
    show(s);
    cout<<deQueue(s,e)<<endl;
    show(s);cout<<deQueue(s,e)<<endl;
    show(s);cout<<deQueue(s,e)<<endl;
    show(s);cout<<deQueue(s,e)<<endl;
    show(s);cout<<deQueue(s,e)<<endl;
    show(s);cout<<deQueue(s,e)<<endl;
    show(s);cout<<deQueue(s,e)<<endl;
    show(s);cout<<deQueue(s,e)<<endl;
    show(s);cout<<deQueue(s,e)<<endl;
    show(s);


    enQueue(s, 1);
    enQueue(s, 2);
    enQueue(s, 3);
    enQueue(s, 4);
    enQueue(s, 5);
    show(s);

    getHead(s,e);
    cout<<e<<"   <------"<<endl;
    show(s);

    deQueue(s,e);
    deQueue(s,e);
    deQueue(s,e);
    deQueue(s,e);
    cout<<isEmpty(s)<<endl;
    deQueue(s,e);


    show(s);
    cout<<isEmpty(s)<<endl;








}

void initQueue(SqQueue &sqQueue) {
    sqQueue.front = sqQueue.rear = 0;
}

bool isEmpty(SqQueue sqQueue) {
    return sqQueue.rear == sqQueue.front;
}

bool enQueue(SqQueue &sqQueue, int e) {
    if ((sqQueue.rear + 1) % MaxSize == sqQueue.front)
        return false;
    sqQueue.data[sqQueue.rear] = e;
    sqQueue.rear = (sqQueue.rear + 1) % MaxSize;
    return true;
}

bool deQueue(SqQueue &sqQueue, int &e) {
    if (sqQueue.rear == sqQueue.front)
        return false;
    e = sqQueue.data[sqQueue.front];
    sqQueue.front = (sqQueue.front + 1) % MaxSize;
    return true;
}

bool getHead(SqQueue sqQueue, int &e) {
    if (sqQueue.rear == sqQueue.front)
        return false;
    e = sqQueue.data[sqQueue.front];
    return true;
}

void show(SqQueue s) {

    if (s.front == s.rear) {
        cout << "空栈" << endl;
        return;
    }
    if (s.front == 0) {
        for (int i = 0; i < MaxSize; ++i) {
            cout << s.data[i] << "   ";
        }
        cout << endl;
        return;
    }
//    int i = s.front;
//    while (i !=s.front-1){
//        cout << s.data[i] << " -----" << i << "----    >"<<s.front<<"<   -------";
//
//        i = (i + 1) % MaxSize;
//    }
    for (int i = s.front; i != s.front - 1;i = (i + 1) % MaxSize) {
        cout << s.data[i] <<"     ";
    }
    cout << endl;
}